package com.tongji.diy.view.component3D
{
	import flare.core.Mesh3D;
	
	import flash.geom.Point;
	import flash.geom.Vector3D;
	
	public class ShapeToAddLWall extends ShapeToAdd
	{
		//无奈之举
		private var initDis:Number;
		
		public function ShapeToAddLWall(roomShapePoints:Vector.<Point>, pos:Vector3D, roomBorder:RoomBorder, name:String = "")
		{
			super(roomShapePoints,pos,roomBorder);
			
			//算点
			var endPos:Point = new Point(roomBorder.end.data.globalX,roomBorder.end.data.globalY);
			var dis:Number = Math.sqrt((endPos.x-pos.x)*(endPos.x-pos.x)+(endPos.y-pos.z)*(endPos.y-pos.z));
			
			initDis=dis;
			
			this._roomShapePoints[0] = (new Point(0,0));
			this._roomShapePoints[1] = (new Point(0,200));
			this._roomShapePoints[2] = (new Point(dis,200));
			this._roomShapePoints[3] = (new Point(dis,0));
			
			/*
			画墙
			*/
			
			//第一面墙
			borders.push(new Mesh3D());
			borders[0] = drawBorder(borders[0],_roomShapePoints[_roomShapePoints.length-1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2]);
			//中间的墙
			borders.push(new Mesh3D());
			borders[1] = drawBorder(borders[1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3]);
			//最后面墙
			borders.push(new Mesh3D());
			borders[2] = drawBorder(borders[2],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3],_roomShapePoints[0]);
			
			/*
			调整位置
			*/
			
			this.setPos(pos,roomBorder);
			this.setRot(roomBorder.getNormal());
		}
		
		override public function refresh(pos:Vector3D,roomBorder:RoomBorder):void
		{
			this._roomBorder = roomBorder;
			
			/*
			 *	设材质
			 */
			
			this._material = roomBorder.material;
			
			//算点
			var endPos:Point = new Point(roomBorder.end.data.globalX,roomBorder.end.data.globalY);
			var dis:Number = Math.sqrt((endPos.x-pos.x)*(endPos.x-pos.x)+(endPos.y-pos.z)*(endPos.y-pos.z));
			
//			this._roomShapePoints[0] = new Point(0,0);
//			this._roomShapePoints[1] = new Point(0,200);
			this._roomShapePoints[2] = new Point(dis,200);
			this._roomShapePoints[3] = new Point(dis,0);
			
			/*
			画墙
			*/
			
			//第一面墙
//			borders[0] = drawBorder(borders[0],_roomShapePoints[_roomShapePoints.length-1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2]);
			//中间的墙
			borders[1] = drawBorder(borders[1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3]);
			//最后面墙
//			borders[2] = drawBorder(borders[2],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3],_roomShapePoints[0]);
			borders[2].x = dis-initDis;
			
			/*
			调整位置
			*/
			
			this.setPos(pos,roomBorder);
			this.setRot(roomBorder.getNormal());
		}
	}
}